
<?php

/*
 Open a connection to the database
*/
$conn = mysql_connect('studentdb.gl.umbc.edu', 'chrimo1', 'chrimo1');
if (!$conn) {
   die('Could not connect');
}

$db_selected = mysql_select_db('chrimo1', $conn);
if (!$db_selected) {
   die ('Can\'t use chrimo1');
}


?>

<html>
<head>
<title>Legacy-Gamer</title>

<link rel="stylesheet" type="text/css" href="legacyGamer.css">

</head>
<body class="body">


<div id="Header" class="style1">
	<div id="sublayer1" >
		<a href="index.php"  style="float:left;"><img src="images/Title.png" height="115px" alt="store logo"></a>
		<a href="cart.php" style="float:right; height:115px; border-left:1px solid #ccc; position:relative;">
			<img src="images/cart.png" alt="store logo">
			<?php
				/*
				 Identify the number of items in the cart
				*/
				$sql = "SELECT * FROM shoppingCart WHERE custIdNum='".$_COOKIE['user']."'";
				$result = mysql_query($sql, $conn);
				echo '<h2 style="position: absolute; top:10px">&nbsp &nbsp'.mysql_num_rows($result).'</h2>';

			?>
		</a>
		<?php
			echo '<div style="font-size:10pt; color:#FFC80E; float:right;" align="right">Welcome, '.$_COOKIE["user"].'<br><a href="login.php?logout=1" >Logout</a></div>';
		?>
		
	</div>	
</div>
	
<div id="Layer2" class="style2" align="left" >
	<ul id="nav">
	  <h3 style="height:10px; color:#FFC80E;">Genre:</h3>
	  <li2><a href="listItems.php?id=BeatemUp">
 		Beat'em Up
	  </a></li2>
	  <li2><a href="listItems.php?id=RPG">
 		RPG
	  </a></li2>
	  <li2><a href="listItems.php?id=Platform">
 		Platform
	  </a></li2>
	  <li2><a href="listItems.php?id=Action">
 		Action
	  </a></li2>
	  <li2><a href="listItems.php?id=PuzzleStrategy">
 		Puzzle/Strategy
	  </a></li2>
	  <li2><a href="listItems.php?id=ShootemUp">
 		Shoot'em Up
	  </a></li2>
	  <li2><a href="listItems.php?id=CityBuildingSimulator">
 		City Building Simulator
	  </a></li2>
	  <li2><a href="listItems.php?id=ScrollingShooter">
 		Scrollling Shooter
	  </a></li2>
	  <li2><a href="listItems.php?id=Racing">
 		Racing
	  </a></li2>
	  <li2><a href="listItems.php?id=Sports">
 		Sports
	  </a></li2>
	  
	  <h3 style="height:10px; color:#FFC80E;">System:</h3>
	  <li2><a href="listItems.php?id=Sega">
 		Sega Genesis
	  </a></li2>
	  <li2><a href="listItems.php?id=SuperNintendo">
 		Super Nintendo
	  </a></li2>

	  <h3 style="height:10px; color:#FFC80E;">Player Modes:</h3>
	  <li2><a href="listItems.php?id=Single">
 		Single-Player
	  </a></li2>
	  <li2><a href="listItems.php?id=Multi">
 		MultiPlayer
	  </a></li2>
	  <li2><a href="listItems.php?id=Coop">
 		Cooperative
	  </a></li2>

	</ul>
</div>

<div id="Layer3" style="color:#FFC80E; margin-left:5px; margin-top:0px; position:absolute; min-width:978px; height:625px; z-index:1; left:175px; top:115px; overflow:inheret; max-width:89%;" align="left"> 
  <form method="get" action="search.php">
    <input style="width:72%;" type="text" name="search">  
    <input type="submit" value="Search">
    <?php 
	$itemID = $_GET['id'];
	
	/*
	 Create a query to get details of the game based on the game ID
	*/

	$sql = "SELECT * FROM gameInventory WHERE idNum=".$itemID;
	

	$result = mysql_query($sql, $conn);
	if (mysql_num_rows($result)==0){
 	  echo '<center><h2>Game does not exist.</h2></center>';
	  die();
	}
	
	
	/*
	 Post details of the game and an option to add the game to the cart
	*/
	while($r = mysql_fetch_array($result))
   	{
         $idNum = $r['idNum'];
         $gameName = $r['gameName'];
         $developer = $r['developer'];
         $releaseDate = $r['releaseDate'];
         $qty = $r['quantity'];
         $price = $r['price'];
	  $image = $r['imageURL'];
	  $description = $r['description'];
	  $cooperative = $r['cooperative'];
	  $multiplayer = $r['multiplayer'];
	  $singleplayer = $r['singleplayer'];

	  if($r['system'] == snes){
	    $console = "Super Nintendo";
	  }
	  else{
	    $console = "Sega Genesis";
	  }
	  echo '<h2 style="color:#FFC80E;">'; echo $gameName; echo '</h2>';
	  echo '<table style="color:#FFC80E;"><tr><td><img src="'; echo $image; echo '" height="250px" ></td>';
	  echo '<td><p style="color:#FFC8OE;">Price: &nbsp; $'; echo $price;
	  echo '<br>Release Date: &nbsp; '; echo $releaseDate;
	  echo '<br>Developer: &nbsp; '; echo $developer;
	  echo '<br>Player Modes:';
	  if($singleplayer == 1){
	  	echo '<br>&nbsp;&nbsp;&nbsp;Single-Player';
	  }
	  if($multiplayer == 1){
	  	echo '<br>&nbsp;&nbsp;&nbsp;Multiplayer';
	  }
	  if($cooperative == 1){
	  	echo '<br>&nbsp;&nbsp;&nbsp;Cooperative';
	  }
	  if($r['system'] == sega){
	  	echo '<br>System: &nbsp; Sega Genesis';
	  }
	  else{
	  	echo '<br>System: &nbsp; Super Nintendo';
	  }
	  echo '<br>Quantity In Stock: &nbsp; '; echo $qty;
	  echo '<br><br><a href="cart.php?addId='.$idNum.'" height="31px" width="91px" class="button">Add to Cart</a>';
	  echo '</p></td></tr></table>';  
	  echo '<h3 style="color:#FFC80E;">Description:</h3>';
         echo '<p style="max-width:75%;">'; echo $description; echo '</p>';
       }

    ?>    

  </form>
</div>

</body>

</html>
